package com.zy.design.ocp.ns;

import com.zy.design.ocp.base.Notification;
import com.zy.design.ocp.base.NotificationEmergencyLevel;

/**
 * @author zhaoyi
 * @date 2021/3/15 18:20
 *
 * 改动二：添加新的 handler
 */
public class TimeoutAlertHandler extends AlertHandler {


    public TimeoutAlertHandler(AlertRule2 rule, Notification notification) {
        super(rule, notification);
    }

    @Override
    public void check(ApiStatInfo apiStatInfo) {
        if (apiStatInfo.getTimeoutCount() / apiStatInfo.getDurationOfSeconds() > rule.getMatchedRule(apiStatInfo.getApi()).getMaxTimeoutTps()) {
            notification.notify(NotificationEmergencyLevel.URGENCY, "... TimeoutAlertHandler");
        }
    }
}
